package com.hs.core;/*
 *@author:guozhijiang
 *@create:2021-03-29 14:36
 */


import org.slf4j.LoggerFactory;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import org.slf4j.Logger;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class MainFram {

    private final Logger logger = LoggerFactory.getLogger(MainFram.class);
    private final JFrame frame;
    private final JButton pauseButton;//暂停按钮
    private final JButton forwardButton;//转发


    public MainFram (final EmbeddedMediaPlayerComponent mediaPlayerComponent,String stream){
        logger.debug("视频流地址为："+stream);
        System.out.println("jjjff");
        frame = new JFrame("视频播放器");
        frame.setBounds(500, 300, 600, 400);
        frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                mediaPlayerComponent.release();
                System.exit(0);
            }
        });

        JPanel contentPane = new JPanel();
        contentPane.setLayout(new BorderLayout());

        contentPane.add(mediaPlayerComponent, BorderLayout.CENTER);

        JPanel controlsPane = new JPanel();
        pauseButton = new JButton("暂停/播放");
        controlsPane.add(pauseButton);
        forwardButton = new JButton("转发");
        controlsPane.add(forwardButton);
        contentPane.add(controlsPane, BorderLayout.SOUTH);
        pauseButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                mediaPlayerComponent.getMediaPlayer().pause();
            }
        });

        forwardButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new Thread(){
                    @Override
                    public void run(){
                        Forward.start();
                    }
                }.start();
                logger.debug("视频流转发线程已启动");
            }
        });
        frame.setContentPane(contentPane);
        frame.setVisible(true);
        mediaPlayerComponent.getMediaPlayer().playMedia(stream);
    }
}
